package com.ruoyi.logistic.controller;

import com.github.pagehelper.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.logistic.domain.NetworkMyAccount;
import com.ruoyi.logistic.domain.NetworkPrePayDealSheet;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.logistic.domain.vo.NetworkMyAccountVo;
import com.ruoyi.logistic.service.NetworkMyAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/network/myAccount")
@RestController
@Api(tags = "网点财务_站点预付款_我的账户")
public class NetworkMyAccountController {
    @Autowired
    private NetworkMyAccountService networkMyAccountService;
    @Autowired
    private TableService tableService;

    @ApiOperation("显示我的账户列表")
    @GetMapping("/selectAll")
    public R selectAll(PageDate pageDate){
        List<NetworkMyAccount> networkMyAccountList = networkMyAccountService.selectAll(pageDate);
        if (networkMyAccountList == null || networkMyAccountList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(networkMyAccountList));
        }
    }

    @ApiOperation("添加我的账户")
    @PostMapping("/insert")
    public R insert(@RequestBody NetworkMyAccount networkMyAccount){
        Boolean isAdd = networkMyAccountService.insert(networkMyAccount);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }

    @ApiOperation("修改我的账户")
    @PostMapping("/update")
    public R update(@RequestBody NetworkMyAccount networkMyAccount){
        Boolean isUpdate = networkMyAccountService.update(networkMyAccount);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }

    @ApiOperation("删除我的账户")
    @PostMapping("/deleteById")
    public R deleteById(Integer id){
        Boolean isDelete = networkMyAccountService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }

    @ApiOperation("搜索我的账户")
    @PostMapping("/search")
    public R search(@RequestBody NetworkMyAccountVo networkMyAccountVo) {
        List<NetworkMyAccount> networkMyAccountList = networkMyAccountService.search(networkMyAccountVo);
        List<TableVo> fieldList = tableService.getFieldAnnotation(new NetworkMyAccount());
        com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
        jsonObject.put("list", PageInfo.info(networkMyAccountList));
        jsonObject.put("fields", fieldList);
        if (networkMyAccountList == null || networkMyAccountList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(jsonObject);
        }
    }
}
